package com.zwj.dao.impl;

import com.zwj.bean.Order;
import com.zwj.dao.BaseDao;
import com.zwj.dao.OrderDao;

import java.util.List;

/**
 * @author zwj
 * @create 2021-05-16-9:51
 */
public class OrderDaoImpl extends BaseDao implements OrderDao {
    @Override
    public int saveOrder(Order order) {
        String sql = "insert into t_order(`order_id`,`create_time`,`price`,`status`,`user_id`) values(?,?,?,?,?)";
        return update(sql,order.getOrderId(),order.getCreateTime(),order.getPrice(),order.getStatus(),order.getUserId());
    }

    @Override
    public List<Order> queryOrdersByUserId(Integer uerId) {
        String sql = "SELECT `order_id` orderId,`create_time` createTime,`price`,`status`,`user_id` userId FROM t_order WHERE user_id = ?";
        return queryForList(Order.class,sql,uerId);
    }

    @Override
    public List<Order> queryAllOrders() {
        String sql = "SELECT `order_id` orderId,`create_time` createTime,`price`,`status`,`user_id` userId FROM t_order";
        return queryForList(Order.class,sql);
    }

    @Override
    public int changeOrderStatus(String orderId, Integer status) {
        String sql = "UPDATE t_order SET `status` = ? WHERE `order_id` = ?";
        return update(sql,status,orderId);
    }
}
